package com.beiding.businessplatform.ql;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

//选择器
public class SelectionBuilderImpl implements SelectionBuilder {

    //选择的列表
    private Set<QueryField> select = new HashSet<>();

    public Set<QueryField> getSelect() {
        return select;
    }

    @Override
    public void setSelect(Set<QueryField> select) {
        this.select = select;
    }

    public void addSelect(QueryField field) {
        select.add(field);
    }

    @Override
    public void build(BuilderHolder holder) {
        Iterator<QueryField> iterator = select.iterator();
        if (iterator.hasNext()) {
            QueryField field = iterator.next();
            holder.appendSelect(field.getKey()).appendSelect(" as ").appendSelect(field.getAs());
            while (iterator.hasNext()) {
                field = iterator.next();
                holder.appendSelect(" , ").appendSelect(field.getKey()).appendSelect(" as ").appendSelect(field.getAs());

            }
        }
    }
}
